﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace _16一对多;

public class MyContext:DbContext
{
    public DbSet<Article> Articles { get; set; }
    public DbSet<Comment> Comments { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
        optionsBuilder.UseSqlServer(
            "Server=.;Database=efCorePractice_2;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=true;"
            );
        optionsBuilder.LogTo((message) =>
        {
            Console.WriteLine(message);
        },LogLevel.Information);
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
    }
}